package com.xyc.servlet.song;

import com.xyc.mapper.SongMapper;
import com.xyc.pojo.Song;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/findSong")
public class FindSongServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String id = req.getParameter("id_update");
        ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-dao.xml");
        SongMapper songMapper = ctx.getBean("songMapper", SongMapper.class);
        Song song = songMapper.selectSongById(id);
        req.setAttribute("song", song);
        //System.out.println("需要修改的歌曲:"+song);
        req.getRequestDispatcher("user/updateSong.jsp").forward(req, resp);
    }
}
